package com.lesso.lzh.sunflower.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.lzh.sunflower.core.ApiResponse;
import com.lesso.lzh.sunflower.pojo.dto.AttendanceRuleDTO;
import com.lesso.lzh.sunflower.pojo.dto.AttendanceRuleQueryDTO;
import com.lesso.lzh.sunflower.pojo.vo.AttendanceRuleVO;
import com.lesso.lzh.sunflower.pojo.vo.EmployeeVO;
import com.lesso.lzh.sunflower.service.IAttendanceRuleService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 考勤规则基础信息 前端控制器
 * </p>
 *
 * @author zqz
 * @since 2025-07-04
 */
@RestController
@RequestMapping("/base/attendance-rule")
public class AttendanceRuleController {
    @DubboReference
    private IAttendanceRuleService attendanceRuleService;

    @PostMapping
    public ApiResponse<Long> save(@RequestBody AttendanceRuleDTO dto) {
        try {
            return ApiResponse.<Long>ok().data(attendanceRuleService.save(dto)).build();
        } catch (Exception e) {
            return ApiResponse.<Long>error().msg("保存考勤规则信息失败: " + e.getMessage()).build();
        }
    }

    @GetMapping("/page")
    public ApiResponse<Page<AttendanceRuleVO>> page(AttendanceRuleQueryDTO dto) {
        try {
            return ApiResponse.<Page<AttendanceRuleVO>>ok()
                    .data(attendanceRuleService.page(dto))
                    .build();
        } catch (Exception e) {
            return ApiResponse.<Page<AttendanceRuleVO>>error().msg("分页查询考勤规则信息失败: " + e.getMessage()).build();
        }
    }

    @GetMapping("/custom/page")
    public ApiResponse<Page<AttendanceRuleVO>> customPage(AttendanceRuleQueryDTO dto) {
        try {
            return ApiResponse.<Page<AttendanceRuleVO>>ok().data(attendanceRuleService.customPage(dto)).build();
        } catch (Exception e) {
            return ApiResponse.<Page<AttendanceRuleVO>>error().msg("自定义分页查询考勤规则信息失败: " + e.getMessage()).build();
        }
    }

    @DeleteMapping
    public ApiResponse<Object> delete(@RequestParam("id") Long id) {
        try {
            attendanceRuleService.deleteById(id);
            return ApiResponse.ok().build();
        } catch (Exception e) {
            return ApiResponse.error().msg("删除考勤规则信息失败: " + e.getMessage()).build();
        }
    }

    @GetMapping
    public ApiResponse<Object> selectById(@RequestParam("id") Long id) {
        try {
            Object result = attendanceRuleService.selectById(id);
            return ApiResponse.ok().data(result).build();
        } catch (Exception e) {
            return ApiResponse.error().msg("查询考勤规则信息失败: " + e.getMessage()).build();
        }
    }

    @PutMapping
    public ApiResponse<Object> update(@RequestBody AttendanceRuleDTO dto) {
        try {
            attendanceRuleService.update(dto);
            return ApiResponse.ok().build();
        } catch (Exception e) {
            return ApiResponse.error().msg("更新考勤规则信息失败: " + e.getMessage()).build();
        }
    }

}